//
// Created by Semir on 2020/4/26.
//

#include <iostream>
#include <algorithm>

using namespace std;

struct Line {
    int begin;
    int end;
};

const int MAX_N = 100000;
int n;
Line* lines[MAX_N];

bool cmp(Line* line1, Line* line2) {
    return line1->end < line2->end;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        lines[i] = new Line;
        cin >> lines[i]->begin;
        cin >> lines[i]->end;
    }
    sort(lines, lines + n, cmp);
    int cur = 0;
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (cur <= lines[i]->begin) {
            cur = lines[i]->end;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}
